package ua.kharkiv.karimov.knure.SummaryTask1.Airplanes;
/**
 * This class describes the "passenger liner"
 * @author Karimov
 *
 */
public class Airliner extends Airplane {

	/**
	 * the maximum number of seats
	 */
	private final int maxNumSeats;

	private final double FUEL_CONSUMPLION_PER_KM;

	/**
	 * the number of seats
	 */
	private int numSeats;

	/**
	 * Create new aircraft model
	 * 
	 * @param fuel
	 *            tons
	 * @param weight
	 *            tons
	 * @param wingspan
	 *            m
	 * @param length
	 *            m
	 * @param height
	 *            m
	 * @param model
	 * @param code
	 * @param speed
	 *            km / h
	 * @param capacity
	 *            m3
	 * @param maxWeight
	 * @param maxNumSeats
	 *            number of passengers
	 */
	public Airliner(double fuel, double weight, double wingspan, double length,
			double height, String model, String code, double speed,
			double capacity, double maxWeight, int maxNumSeats, double fuelPerKm) {
		super(fuel, weight, wingspan, length, height, model, code, speed,
				capacity, maxWeight);
		this.maxNumSeats = maxNumSeats;
		this.FUEL_CONSUMPLION_PER_KM = fuelPerKm;
	}

	public String getStatus() throws Exception {
		switch (compare()) {
		case -2:
			return getCode() + ": start from [" + getAirportFrom().getName()
					+ "]";
		case -1:
			return getCode() + ": parked at the airport ["
					+ getAirportFrom().getName() + "]";
		case 0:
			return getCode() + ": flying at [" + getCoord() + "]";
		case 1:
			return getCode() + ": parked at the airport ["
					+ getAirportTo().getName() + "]";
		case 2:
			return getCode() + ": to land in [" + getAirportTo().getName()
					+ "]";
		default:
			break;
		}
		return null;
	}

	/**
	 * Compare 3 coordinates (this, port1, port2)
	 * 
	 * @return <li>-2 if this coord near with port1</li> <li>-1 if parked at the
	 *         airport port1</li> <li>0 if in the middle</li> <li>1 if parked at
	 *         the airport port2</li> <li>2 if this coord near with port2</li>
	 * @throws Exception
	 *             if coord null
	 */
	public int compare() throws Exception {
		int land = 10;
		if (getCoord() == null)
			throw new Exception("coord is null");
		Coord c2 = getAirportFrom().getCoord();
		Coord c3 = getAirportTo().getCoord();
		double d1 = getCoord().lengthTo(c2);
		double d2 = getCoord().lengthTo(c3);
		double d3 = c2.lengthTo(c3);
		if (getCoord().equals(c2))
			return -1;
		if (getCoord().equals(c3))
			return 1;
		if (d3 < land * 2 && d1 < d2)
			return -2;
		if (d3 < land * 2 && d1 > d2)
			return 2;
		if (d1 < land)
			return -2;
		if (d2 < land)
			return 2;
		return 0;
	}

	@Override
	public String toString() {
		return "coord: [" + getCoord() + "]\t" + "model: [" + getModel()
				+ "]\t" + "airport from: [" + getAirportFrom() + "]\t"
				+ "airport to: [" + getAirportTo() + "]";
	}

	/**
	 * the maximum number of seats
	 */
	public int getMaxNumSeats() {
		return maxNumSeats;
	}

	/**
	 * the number of seats
	 */
	public int getNumSeats() {
		return numSeats;
	}

	/**
	 * the number of seats
	 */
	public void setNumSeats(int numSeats) {
		this.numSeats = numSeats;
	}

	public Craft getModelCopy(String code) {
		return new Airliner(fuel, weight, wingspan, length, height, model,
				code, speed, capacity, maxWeight, maxNumSeats, FUEL_CONSUMPLION_PER_KM);
	}

	public double getFuelPerKm() {
		return FUEL_CONSUMPLION_PER_KM;
	}

}
